/**
 * Definition for a binary tree node.
 * public class TreeNode {
 *     int val;
 *     TreeNode left;
 *     TreeNode right;
 *     TreeNode() {}
 *     TreeNode(int val) { this.val = val; }
 *     TreeNode(int val, TreeNode left, TreeNode right) {
 *         this.val = val;
 *         this.left = left;
 *         this.right = right;
 *     }
 * }
 */
class code2 {
    //求根节点到叶节点数字之和
    public int sumNumbers(TreeNode root) {
        return dfs(root,0);
    }
    public int dfs(TreeNode root,int prum) {
        //1.拿到125=12*10+5
        prum = prum*10+root.val;
        //递归出口（在第一步之后）
        if(root.left==null&&root.right==null) return prum;

        int ret = 0;
        //2.左加和
        if(root.left!=null) ret += dfs(root.left,prum);
        //3.右加和
        if(root.right!=null) ret += dfs(root.right,prum);
        //4.返回和
        return ret;

    }
}